#!/bin/sh

prefix="/opt"
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin

start() {
	echo "starting mjpg_streamer..."
	# Do not forget to load nececcery kernel modules,
	# in case of using UVC-compliant camera:
	#insmod videodev
	#insmod v4l2-common
	#insmod v4l2-int-device
	#insmod input-core
	#insmod uvcvideo
	yes | mjpg_streamer -b -i "input_uvc.so -r 320x240 -f 5" -o "output_http.so -p 3000 -w /opt/share/www/webcam"
	}

stop() {
	echo "stopping mjpg_streamer..."
	killall mjpg_streamer
	}

status() {
	echo "PID of mjpg_streamer is..."
	pidof mjpg_streamer
	}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 3
		start
		;;
	status) status
		;;
	*)
		echo "Usage: $0 (start|stop|restart|status)"
		exit 1
		;;
esac

exit 0
